/** 
 * File-Name:JDKCrawler.java
 *
 * Created on 2011-5-6 上午10:16:12
 * 
 * @author: Neo (neolimeng@gmail.com)
 * Software Engineering Institute, Peking University, China
 * 
 * Copyright (c) 2009, Peking University
 * 
 *
 */
package com.exceptionhandler.service.crawl;

import java.util.ArrayList;
import java.util.List;

import org.neocrawler.entity.WebContent;
import org.neocrawler.parser.IParser;

import data.processor.URLFilter;

/**
 * Description:
 * 
 * @author: Neo (neolimeng@gmail.com) Software Engineering Institute, Peking
 *          University, China
 * @version 1.0 2011-5-6 上午10:16:12
 */
public class JDKCrawler extends ExceptionCrawler implements IParser {
	// ========== Required!!!! ========== //
	private static final String PROJECT_NAME = "JDK";
	private static final String PARSER_CLASS_NAME = JDKCrawler.class.getName();
	private static String SEED_URLS = "http://www.java-forums.org/";

	// ========== Optional ========== //
	private static final String STORE_PATH = BASE_STORE_PATH + PROJECT_NAME
			+ "\\";
	private static final boolean USE_PROXY_OR_NOT = true;
	private static final int THREAD_NUM = 4;
	private static final String PROXY_URL = "192.168.4.31";
	private static final int PROXY_PORT = 3128;

	public JDKCrawler() {
		super(PROJECT_NAME, SEED_URLS, STORE_PATH, PARSER_CLASS_NAME,
				THREAD_NUM, USE_PROXY_OR_NOT, PROXY_URL, PROXY_PORT);
	}

	// ===== Apache Mail Archive Configurations ===== //

	@Override
	public List<WebContent> getInitialSeeds() {
		// No needed in this class.
		return null;
	}

	@Override
	public List<WebContent> parse(WebContent webContent, String webPage) {
		List<WebContent> webContents = URLFilter
				.getWebContentList_JAVAFORUM(webPage);
		if (webContents == null) {
			return null;
		} else {
			List<WebContent> results = new ArrayList<WebContent>();
			for (int i = 0; i < webContents.size(); i++) {
				try {
					WebContent w = webContents.get(i);
					w.setParentUrl(webContent.getUrl());
					w.setParentUuid(webContent.getUuid());
					w.setReserve02(PROJECT_NAME);
					results.add(w);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return results;
		}
	}

	/**
	 * Description:
	 * 
	 * @param args
	 *            void
	 */
	public static void main(String[] args) {
		JDKCrawler crawler = new JDKCrawler();
		crawler.start();
		// crawler.restart();
	}

}
